# -*-coding = utf-8 -*-
# @Time : 2023/4/16 23:23
# @Author : Oliver
# @File : 04决策树与随机森林.py
# @Software :PyCharm

import numpy as np
import matplotlib.pyplot as plt

# 两点分布的信息熵
eps = 1e-4
p = np.linspace(eps, 1 - eps, 100)
entropy = -(1 - p) * np.log(1 - p) - p * np.log(p)
gini = 2 * (1 - p) * p
plt.title('entropy(red) & gini(green)')
plt.plot(p, entropy, 'r-', lw=3)
plt.plot(p, gini, 'g-', lw=3)
plt.show()
